package frontend.user.product.manager;

import java.util.List;

import org.hibernate.Session;
import core.product.model.ProductOwner;
import core.profile.model.BasicProfile;
import core.util.HibernateCoreUtil;

public class UserProductManager 
{
	public List<ProductOwner> getUserProducts(BasicProfile owner)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<ProductOwner> prodOwners = (List<ProductOwner>) session.createQuery("from ProductOwner where owner=:o").setEntity("o", owner).list();
		session.getTransaction().commit();
		return prodOwners;
	}
	public List<ProductOwner> getManagerProducts(BasicProfile manager)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<ProductOwner> prodOwners = (List<ProductOwner>) session.createQuery("from ProductOwner where manager=:manager").setEntity("manager", manager).list();
		session.getTransaction().commit();
		return prodOwners;
	}
	public void save(ProductOwner po)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(po);
		session.getTransaction().commit();
	}
}
